<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="font-size: 25px">添加学生信息</span>
        <el-button style="margin-left: 20px" size="mini" type="primary"
          >批量导入</el-button
        >
      </div>
      <el-form ref="form" :model="studentInfo" label-width="80px">
        <el-form-item label="学号" style="width: 400px">
          <el-input
            v-model="studentInfo.studentid"
            placeholder="请输入学号"
          ></el-input>
        </el-form-item>
        <el-form-item label="姓名" style="width: 400px">
          <el-input
            v-model="studentInfo.name"
            placeholder="请输入姓名"
          ></el-input>
        </el-form-item>
        <el-form-item label="年级" style="width: 400px">
          <el-input
            v-model="studentInfo.grade"
            placeholder="请输入年级"
          ></el-input>
        </el-form-item>
        <el-form-item label="专业">
          <el-select v-model="studentInfo.major" placeholder="请选择专业">
            <el-option
              label="计算机科学与技术"
              value="计算机科学与技术"
            ></el-option>
            <el-option
              label="计算机科学与技术+智能科学与技术"
              value="计算机科学与技术+智能科学与技术"
            ></el-option>
            <el-option label="软件工程" value="软件工程"></el-option>
            <el-option
              label="软件工程（中外合作）"
              value="软件工程（中外合作）"
            ></el-option>
            <el-option label="网络工程" value="网络工程"></el-option>
            <el-option label="数字媒体技术" value="数字媒体技术"></el-option>
            <el-option label="物联网工程" value="物联网工程"></el-option>
            <el-option
              label="数据科学与大数据技术"
              value="数据科学与大数据技术"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">添加</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import adminControll from "@/api/adminControll";
export default {
  data() {
    return {
      studentInfo: {
        studentid: "",
        name: "",
        grade: "",
        major: "",
      },
    };
  },

  components: {},

  computed: {},

  mounted() {},

  methods: {
    //插入学生操作
    insertStudent(studentInfo) {
      adminControll.adminInsetStudent(studentInfo).then((response) => {
        if (response.code == "200") {
          this.$message({
            type: "success",
            message: "添加成功",
          });
        } else {
          this.$message({
            type: "error",
            message: "添加失败",
          });
        }
      });
    },
    onSubmit() {
      const { studentid, name, grade, major } = this.studentInfo;
      if (studentid && name && grade && major)
        this.insertStudent(this.studentInfo);
      else {
        alert("请输入完整的信息");
      }
    },
  },
};
</script>
<style scoped></style>
